package svc

import (
	"github.com/zeromicro/go-zero/core/stores/postgres"
	"go-zero-demo-04/mall/user/rpc/internal/config"
	"go-zero-demo-04/mall/user/rpc/model"
)

type ServiceContext struct {
	Config          config.Config
	CollegeModel    model.CollegeModel
	DeportmentModel model.DepartmentModel
	ClassModel      model.ClassModel
	StudentModel    model.StudentModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := postgres.New(c.DB.DataSource)
	return &ServiceContext{
		Config:          c,
		StudentModel:    model.NewStudentModel(conn, c.Cache),
		CollegeModel:    model.NewCollegeModel(conn, c.Cache),
		DeportmentModel: model.NewDepartmentModel(conn, c.Cache),
		ClassModel:      model.NewClassModel(conn, c.Cache),
	}
}
